-- Thanks to Kogitsune for this!
function _R.Player:SpinTo( deg, time )
	self.__spin_deg = deg
	self.__spin_time = time
	self.__spin = true
	self.__pitch = self:GetAngles( ).p
end

local function umSpinTo( um )
	local a, b

	a = um:ReadFloat( )
	b = um:ReadFloat( )

	LocalPlayer():SpinTo( a, b )
end

usermessage.Hook( "Spin To", umSpinTo )

local function CalcView( pl, pos, ang, fov )
	local view
	
	if not pl.__spin then
		return
	end
	
	view = GAMEMODE:CalcView( pl, pos, ang, fov )
	
	pl.__pitch = math.Approach( pl.__pitch, pl.__spin_deg, FrameTime( ) * pl.__spin_time * pl.__spin_deg )
	
	if pl.__pitch == pl.__spin_deg then
		pl.__spin = false
	end
	
	view.angles.p = pl.__pitch
	
	return view
end

hook.Add( "CalcView", "Spin View.CalcView", CalcView )